package cn.engage.basic.util;

import cn.engage.basic.config.BussinessException;
import cn.engage.org.domain.Shop;
import cn.engage.org.domain.ShopAuditLog;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.internet.MimeMessage;

public class MailUtil {

    public static void petHomeMail(JavaMailSender sender, ShopAuditLog shopAuditLog, Shop shop){
        // 发送邮件
        // 1.创建复杂邮件对象

        MimeMessage mimeMessage = sender.createMimeMessage();
        // 2.发送复杂邮件的工具类
        MimeMessageHelper helper = null;
        try {
            helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1075053212@qq.com");
            helper.setSubject("宠物之家审核结果通知");
            if (shop.getState() == -1){
                // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
                helper.setText("<h1>审核未通过，点击下方链接修改店铺信息</h1>"+
                        "http://localhost:8081/#/RegisterAgain?id="+shop.getId(),true);
            }else {
                // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
                helper.setText("<h1>恭喜您审核通过，点击下方链接激活店铺</h1>"+
                        "http://localhost:8080/shop/active/"+shopAuditLog.getShopId(),true);
            }




            // 5.设置收件人
            helper.setTo("1075053212@qq.com");
        } catch (Exception e) {
            throw new BussinessException("发送邮件错误！");
        }
        // 6.发送邮件
        sender.send(mimeMessage);
    }
}

